-
Notifications
You must be signed in to change notification settings - Fork 59
fix: dynamic import issues with esbuild #620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9df6622 to
576065c
Compare
commit: |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 3 files
joaopcm
approved these changes
Sep 15, 2025
fec45e7 to
0b29f9b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #587. Cloudflare Workers uses esbuild under the hood to bundle the code, and esbuild always tries to bundle in imports, even if they are dynamic imports. This means that, if the dynamic import is done to a dependency that is not available, it will error, like
This means that it breaks our shanenigans with try-catch on the import for
renderand avoiding it being imported without thereactoption.The thing is that, as this comment from Evan Wallace mentions evanw/esbuild#3216 (comment), esbuild has heuristics to not error when there is some sort of error handling for the dynamic import, which also includes the sort of syntax we are using. The reason it still fails, is because we are building with tsup for a target bellow
es2017which doesn't support async-await, and so for the built code to work it uses a different sort of generator syntax.This isn't really caught by the heuristics for esbuild, so this pull request handles the errors with
.then/.catch. This does seem to do the trick quite from what I've tested trying to deploy something with Cloudflare Workers in the preview version of this pull request.Summary by cubic
Fixes esbuild bundling failures with dynamic imports in Cloudflare Workers by replacing async/await with a then/catch wrapper and centralizing rendering. Optional @react-email/render no longer breaks builds when not installed.
Bug Fixes
Refactors